package team.sun.sss.common.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import team.sun.sss.common.domain.AjaxResult;
import team.sun.sss.common.domain.TableDataInfo;
import team.sun.sss.common.domain.custom.Custom;
import team.sun.sss.common.entity.NewStudentEntity;
import team.sun.sss.common.entity.StudentEntity;
import team.sun.sss.common.service.NewStudentService;
import team.sun.sss.common.service.StudentConService;
import team.sun.sss.pojo.user.User;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;


/**
 * (迎新)报到信息登记表
 *
 * @author hlj
 * @email hlj@gmail.com
 * @date 2021-04-11 13:07:59
 */
@Controller
@RequestMapping("/common/personal")
public class PersonalController extends BaseController {
    private String baseUrl="personal/";
    @Autowired
    private NewStudentService newStudentService;
    @Autowired
    private StudentConService studentService;
    @Autowired
    private Custom custom;
    @RequestMapping("/view")
    public String toUpdateFamily() {
        return baseUrl+"personal";
    }
    /**
     * 查询学生列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StudentEntity studentEntity, HttpSession session)
    {

        startPage();
        User user = (User) session.getAttribute("loginInfo");
        List<StudentEntity> list = studentService.queryStudentByStuId(user.getUserId());
        return getDataTable(list);
    }

    /**
     * 修改个人数据
     */
    @GetMapping("/edit/{id}/{stuId}")
    public String edit(@PathVariable("id") Long id,@PathVariable("stuId") int stuId, ModelMap mmap)
    {
        mmap.put("stuId",stuId );
        if (!id.equals(new Long(999999)))
        {
            mmap.put("per",newStudentService.getById(id) );
        }
        else
        {
            mmap.put("per", null);
        }

        return baseUrl + "/edit";
    }
    /**
     * 修改个人数据
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewStudentEntity studentEntity)
    {
        studentEntity.setCreateTime(new Date());
        if(studentEntity.getId().equals(new Long(999999)))
        {
            studentEntity.setId(null);
        }
        return toAjax(newStudentService.saveOrUpdate(studentEntity));
    }

}
